package android.mobilin;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Menu extends Activity implements OnClickListener {
	Button request;
	Button view;
	Button settings;
	Button exit;
	Intent action;
	DBAdapter db;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		request=(Button)findViewById(R.id.request);
		view=(Button)findViewById(R.id.view);
		settings=(Button)findViewById(R.id.settings);
		exit=(Button)findViewById(R.id.exit);
		request.setOnClickListener(this);
		view.setOnClickListener(this);
		settings.setOnClickListener(this);
		exit.setOnClickListener(this);
		action=new Intent();
		db=new DBAdapter(this);
	}

	public void onClick(View v) {
		if(v==request) {
			action.setClass(this, RequestActivity.class);
			startActivity(action);
		}
		else if(v==view) {
			Cursor c=db.query("form");
			if(c!=null) {
	    		if(!c.moveToNext()) {
	    			Toast.makeText(this, "No referral form yet.", Toast.LENGTH_SHORT).show();
	    		}
	    		else {
	    			action.setClass(this, ViewActivity.class);
	    			startActivity(action);
	    		}
	    	}
		}
		else if(v==settings) {
			action.setClass(this, SettingsActivity.class);
			startActivity(action);
		}
		else if(v==exit) {
			finish();
		}
	}
	
	
}
